package com.ruoyi.statistics.service.impl;

import com.ruoyi.channel.domain.MpChannel;
import com.ruoyi.channel.mapper.MpChannelMapper;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.merchant.domain.MpMerchant;
import com.ruoyi.merchant.domain.MpMerchantRSP;
import com.ruoyi.merchant.mapper.MpMerchantMapper;
import com.ruoyi.statistics.domain.StatisticsWithdrawal;
import com.ruoyi.statistics.mapper.StatisticsWithdrawalMapper;
import com.ruoyi.statistics.service.IStatisticsWithdrawalService;
import com.ruoyi.transaction.domain.TransactionWithdrawal;
import com.ruoyi.transaction.mapper.TransactionWithdrawalMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 *  服务层实现
 * 
 * @author ruoyi
 * @date 2019-05-07
 */
@Service
public class StatisticsWithdrawalServiceImpl implements IStatisticsWithdrawalService 
{
	Logger log = LoggerFactory.getLogger(StatisticsWithdrawalServiceImpl.class);
	@Autowired
	private StatisticsWithdrawalMapper statisticsWithdrawalMapper;
	@Autowired
	private TransactionWithdrawalMapper withdrawalMapper;
	@Autowired
    private MpMerchantMapper merchantMapper;
	@Autowired
	private MpChannelMapper channelMapper;

	/**
     * 查询信息
     * 
     * @param id ID
     * @return 信息
     */
    @Override
	public StatisticsWithdrawal selectStatisticsWithdrawalById(Long id)
	{
	    return statisticsWithdrawalMapper.selectStatisticsWithdrawalById(id);
	}
	
	/**
     * 查询列表
     * 
     * @param statisticsWithdrawal 信息
     * @return 集合
     */
	@Override
	public List<StatisticsWithdrawal> selectStatisticsWithdrawalList(StatisticsWithdrawal statisticsWithdrawal)
	{
	    return statisticsWithdrawalMapper.selectStatisticsWithdrawalList(statisticsWithdrawal);
	}
	
    /**
     * 新增
     * 
     * @param statisticsWithdrawal 信息
     * @return 结果
     */
	@Override
	public int insertStatisticsWithdrawal(StatisticsWithdrawal statisticsWithdrawal)
	{
	    return statisticsWithdrawalMapper.insertStatisticsWithdrawal(statisticsWithdrawal);
	}
	
	/**
     * 修改
     * 
     * @param statisticsWithdrawal 信息
     * @return 结果
     */
	@Override
	public int updateStatisticsWithdrawal(StatisticsWithdrawal statisticsWithdrawal)
	{
	    return statisticsWithdrawalMapper.updateStatisticsWithdrawal(statisticsWithdrawal);
	}

	/**
     * 删除对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteStatisticsWithdrawalByIds(String ids)
	{
		return statisticsWithdrawalMapper.deleteStatisticsWithdrawalByIds(Convert.toStrArray(ids));
	}


	/**
	 * 统计代付交易信息
	 */
	@Override
	public boolean autoStatisticData(){
		try {
			// 查询代付记录的所有渠道名称
			List<TransactionWithdrawal> channelWithdrawalList = withdrawalMapper.selectTransactionWithdrawalListByChannelName();
			// 查询所有商户名称
            MpMerchant merchant = new MpMerchant(); 
            List<MpMerchantRSP> merchantWithdrawalList = merchantMapper.selectMpMerchantList(merchant);
            // 日期
			// String yesterday = getSelectDate(1);
			String yesterday = "2019-06-09";
			// 全部  渠道为空、商户名称为空    按天
			statisticsWithdrawalByDay(yesterday);
			// 渠道名称	按天
			statisticsWithdrawalByChannelAndDay(channelWithdrawalList, yesterday);
			// 渠道名称	商户名称	按天
			statisticsWithdrawalByChannelAndMerchantAndDay(channelWithdrawalList, merchantWithdrawalList, yesterday);
			// 商户名称	按天
			statisticsWithdrawalByMerchantAndDay(merchantWithdrawalList, yesterday);

			// 统计记录
			// statisticsPay(channelWithdrawalList, merchantWithdrawalList, yesterday);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			log.error("统计异常", e);
			return false;
		}
	}



	/**
	 * 渠道名称 	商户名称  按天
	 */
	public void statisticsPay(List<TransactionWithdrawal> channelWithdrawalList, List<MpMerchantRSP> merchantWithdrawalList,String yesterday) {
		for (TransactionWithdrawal channelWithdrawal : channelWithdrawalList) {
			for (MpMerchantRSP merchantWithdrawal : merchantWithdrawalList) {
				// 预期数据
				TransactionWithdrawal transactionWithdrawalExpect = withdrawalMapper.selectByChannelNameAndMerchantName(channelWithdrawal.getChannelName(), merchantWithdrawal.getName(), yesterday);
				// 实际数据
				TransactionWithdrawal transactionWithdrawalReal = withdrawalMapper.selectByChannelNameAndMerchantNameAndStatus(channelWithdrawal.getChannelName(), merchantWithdrawal.getName(), yesterday, 5);
				// 记录数据
				recordSetStatisticsDataByDay(transactionWithdrawalExpect, transactionWithdrawalReal);
			}
		}
	}




	/**
	 * 	全部  渠道为空、商户名称为空    按天
	 */
	public void statisticsWithdrawalByDay(String yesterday){
		// 预期数据
		TransactionWithdrawal transactionWithdrawalExpect = withdrawalMapper.selectByDay(yesterday);
		// 实际数据
		TransactionWithdrawal transactionWithdrawalReal = withdrawalMapper.selectByDayAndStstus(yesterday, 5);
		// 记录数据
		recordSetStatisticsDataByDay(transactionWithdrawalExpect, transactionWithdrawalReal);
	}




	/**
	 * 渠道名称	按天
	 */
	public void statisticsWithdrawalByChannelAndDay(List<TransactionWithdrawal> channelWithdrawalList, String yesterday){
		if (channelWithdrawalList.size() > 0) {
			for (TransactionWithdrawal transactionWithdrawal : channelWithdrawalList) {
				MpChannel channel = channelMapper.selectOneByName(transactionWithdrawal.getChannelName());
				// 预期数据
				TransactionWithdrawal transactionWithdrawalExpect = withdrawalMapper.selectByChannelAndDay(transactionWithdrawal.getChannelName(),yesterday);
				if (transactionWithdrawalExpect.getChannelName() == null) {
					transactionWithdrawalExpect.setChannelId(channel.getId());
					transactionWithdrawalExpect.setChannelCode(channel.getCode());
					transactionWithdrawalExpect.setChannelName(channel.getName());
				}
				// 实际数据
				TransactionWithdrawal transactionWithdrawalReal = withdrawalMapper.selectByChannelAndDayAndStstus(transactionWithdrawal.getChannelName(),yesterday, 5);
				// 记录数据
				recordSetStatisticsDataByDay(transactionWithdrawalExpect, transactionWithdrawalReal);
			}
		}
	}



	/**
	 * 渠道名称 	商户名称  按天
	 */
	public void statisticsWithdrawalByChannelAndMerchantAndDay(List<TransactionWithdrawal> channelWithdrawalList, List<MpMerchantRSP> merchantWithdrawalList, String yesterday) {
		if (channelWithdrawalList.size() > 0 && merchantWithdrawalList.size() > 0) {
			for (TransactionWithdrawal channelWithdrawal : channelWithdrawalList) {
				for (MpMerchantRSP merchantWithdrawal : merchantWithdrawalList) {
					MpMerchant merchant = merchantMapper.checkMerchantNameUnique(merchantWithdrawal.getName());
					MpChannel channel = channelMapper.selectOneByName(channelWithdrawal.getChannelName());
					// 预期数据
					TransactionWithdrawal transactionWithdrawalExpect = withdrawalMapper.selectByChannelNameAndMerchantName(channelWithdrawal.getChannelName(), merchantWithdrawal.getName(), yesterday);
					if (transactionWithdrawalExpect.getChannelName() == null) {
						transactionWithdrawalExpect.setChannelId(channel.getId());
						transactionWithdrawalExpect.setChannelCode(channel.getCode());
						transactionWithdrawalExpect.setChannelName(channel.getName());
					}
					if (transactionWithdrawalExpect.getMerchantName() == null) {
						transactionWithdrawalExpect.setMerchantId(merchant.getId());
						transactionWithdrawalExpect.setMerchantCode(merchant.getCode());
						transactionWithdrawalExpect.setMerchantName(merchant.getName());
					}
					// 实际数据
					TransactionWithdrawal transactionWithdrawalReal = withdrawalMapper.selectByChannelNameAndMerchantNameAndStatus(channelWithdrawal.getChannelName(), merchantWithdrawal.getName(), yesterday, 5);
					// 记录数据
					recordSetStatisticsDataByDay(transactionWithdrawalExpect, transactionWithdrawalReal);
				}
			}
		}
	}




	/**
	 * 商户名称	按天
	 */
	public void statisticsWithdrawalByMerchantAndDay(List<MpMerchantRSP> merchantWithdrawalList, String yesterday){
		if (merchantWithdrawalList.size() > 0) {
			for (MpMerchantRSP transactionWithdrawal : merchantWithdrawalList) {
				MpMerchant merchant = merchantMapper.checkMerchantNameUnique(transactionWithdrawal.getName());
				// 预期数据
				TransactionWithdrawal transactionWithdrawalExpect = withdrawalMapper.selectByMerchantAndDay(transactionWithdrawal.getName(),yesterday);
				if (transactionWithdrawalExpect.getMerchantName() == null) {
					transactionWithdrawalExpect.setMerchantId(merchant.getId());
					transactionWithdrawalExpect.setMerchantCode(merchant.getCode());
					transactionWithdrawalExpect.setMerchantName(merchant.getName());
				}
				// 实际数据
				TransactionWithdrawal transactionWithdrawalReal = withdrawalMapper.selectByMerchantAndDayAndStstus(transactionWithdrawal.getName(),yesterday, 5);
				// 记录数据
				recordSetStatisticsDataByDay(transactionWithdrawalExpect, transactionWithdrawalReal);
			}
		}
	}


	/**
	 * 封装数据并记录  按天
	 * @param transactionWithdrawalExpect   预期数据
	 * @param transactionWithdrawalReal     实际数据
	 */
   public void recordSetStatisticsDataByDay(TransactionWithdrawal transactionWithdrawalExpect, TransactionWithdrawal transactionWithdrawalReal) {
	   // 统计记录
	   StatisticsWithdrawal statisticsWithdrawal = new StatisticsWithdrawal();
	   if (StringUtils.isNotBlank(transactionWithdrawalExpect.getChannelName())) {
		   statisticsWithdrawal.setChannelId(transactionWithdrawalExpect.getChannelId());
		   statisticsWithdrawal.setChannelName(transactionWithdrawalExpect.getChannelName());
		   statisticsWithdrawal.setChannelCode(transactionWithdrawalExpect.getChannelCode());
	   }else {
		   statisticsWithdrawal.setChannelName("");
	   }

	   if (StringUtils.isNotBlank(transactionWithdrawalExpect.getMerchantName())) {
		   statisticsWithdrawal.setMerchantId(transactionWithdrawalExpect.getMerchantId());
		   statisticsWithdrawal.setMerchantName(transactionWithdrawalExpect.getMerchantName());
		   statisticsWithdrawal.setMerchantCode(transactionWithdrawalExpect.getMerchantCode());
	   }else {
		   statisticsWithdrawal.setMerchantName("");
	   }


	   // 预期数据
	   if (transactionWithdrawalExpect.getChFee() == null) {
		   statisticsWithdrawal.setExpectTimes(transactionWithdrawalExpect.getMerchantNotifyStatus().longValue());
		   statisticsWithdrawal.setExpectFee(new BigDecimal("0.00"));
		   statisticsWithdrawal.setExpectChFee(new BigDecimal("0.00"));
		   statisticsWithdrawal.setExpectMchFee(new BigDecimal("0.00"));
		   statisticsWithdrawal.setExpectFinFee(new BigDecimal("0.00"));
	   }else {
		   statisticsWithdrawal.setExpectTimes(transactionWithdrawalExpect.getMerchantNotifyStatus().longValue());
		   statisticsWithdrawal.setExpectFee(transactionWithdrawalExpect.getSubFee());
		   statisticsWithdrawal.setExpectChFee(transactionWithdrawalExpect.getChFee());
		   statisticsWithdrawal.setExpectMchFee(transactionWithdrawalExpect.getMchFee());
		   statisticsWithdrawal.setExpectFinFee(transactionWithdrawalExpect.getFinFee());
	   }

	   // 实际数据
	   if (transactionWithdrawalReal.getChFee() == null) {
		   statisticsWithdrawal.setRealTimes(transactionWithdrawalReal.getMerchantNotifyStatus().longValue());
		   statisticsWithdrawal.setRealFee(new BigDecimal("0.00"));
		   statisticsWithdrawal.setRealChFee(new BigDecimal("0.00"));
		   statisticsWithdrawal.setRealMchFee(new BigDecimal("0.00"));
		   statisticsWithdrawal.setRealFinFee(new BigDecimal("0.00"));
	   }else {
		   statisticsWithdrawal.setRealTimes(transactionWithdrawalReal.getMerchantNotifyStatus().longValue());
		   statisticsWithdrawal.setRealFee(transactionWithdrawalReal.getFee());
		   statisticsWithdrawal.setRealChFee(transactionWithdrawalReal.getChFee());
		   statisticsWithdrawal.setRealMchFee(transactionWithdrawalReal.getMchFee());
		   statisticsWithdrawal.setRealFinFee(transactionWithdrawalReal.getFinFee());
	   }
	   // 插入时间
	   Calendar calendar = Calendar.getInstance();
	   int day = calendar.get(Calendar.DATE);
	   calendar.set(Calendar.DATE, day);
	   String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
	   statisticsWithdrawal.setStatisticsTime(date);
	   // 统计时间  昨天的数据   天
	   Calendar calendarDateType = Calendar.getInstance();
	   int dayDateType = calendarDateType.get(Calendar.DATE);
	   calendarDateType.set(Calendar.DATE, dayDateType - 1);
	   String dateDateType = new SimpleDateFormat("yyyy-MM-dd").format(calendarDateType.getTime());
	   statisticsWithdrawal.setDateType(dateDateType);
	   // 统计类型
	   statisticsWithdrawal.setStatisticsType(1);
	   // 插入数据
	   statisticsWithdrawalMapper.insertStatisticsWithdrawal(statisticsWithdrawal);
   }







//================================================按小时统计==========================================

	/**
	 * 统计代付交易信息  按小时
	 */
	@Override
	public boolean autoStatisticDataByHours(){
		try {
			// 查询代付记录的所有渠道名称
			List<TransactionWithdrawal> channelWithdrawalList = withdrawalMapper.selectTransactionWithdrawalListByChannelName();
			// 查询所有商户名称
            MpMerchant merchant = new MpMerchant();
			List<MpMerchantRSP> merchantWithdrawalList = merchantMapper.selectMpMerchantList(merchant);
			// 获取昨天的日期  时分秒
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar cal = Calendar.getInstance();
			int day = cal.get(Calendar.DATE);
			cal.set(Calendar.DATE,day -1);
			String endTime = format.format(cal.getTime());
			cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY)-1);
			String startTime = format.format(cal.getTime());
			// 全部  渠道为空、商户名称为空    按天
			statisticsWithdrawalByHours(startTime, endTime);
			// 渠道名称	按天
			statisticsWithdrawalByChannelAndHours(channelWithdrawalList, startTime, endTime);
			// 渠道名称	商户名称	按天
			statisticsWithdrawalByChannelAndMerchantAndHours(channelWithdrawalList, merchantWithdrawalList, startTime, endTime);
			// 商户名称	按天
			statisticsWithdrawalAndHours(merchantWithdrawalList, startTime, endTime);

			// 统计记录
			// statisticsPay(channelWithdrawalList, merchantWithdrawalList, yesterday);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			log.error("统计异常", e);
			return false;
		}
	}



	/**
	 * 	全部  渠道为空、商户名称为空    按小时
	 */
	public void statisticsWithdrawalByHours(String start, String end){
		// 预期数据
		TransactionWithdrawal transactionWithdrawalExpect = withdrawalMapper.selectByHours(start, end);
		// 实际数据
		TransactionWithdrawal transactionWithdrawalReal = withdrawalMapper.selectByDayAndStstusAndHours(start, end, 5);
		// 记录数据
		recordSetStatisticsDataAndHours(transactionWithdrawalExpect, transactionWithdrawalReal);
	}




	/**
	 * 渠道名称	按小时
	 */
	public void statisticsWithdrawalByChannelAndHours(List<TransactionWithdrawal> channelWithdrawalList, String start, String end){
		if (channelWithdrawalList.size() > 0) {
			for (TransactionWithdrawal transactionWithdrawal : channelWithdrawalList) {
				// 预期数据
				TransactionWithdrawal transactionWithdrawalExpect = withdrawalMapper.selectByChannelAndHours(transactionWithdrawal.getChannelName(),start, end);
				// 实际数据
				TransactionWithdrawal transactionWithdrawalReal = withdrawalMapper.selectByChannelAndDayAndStstusAndHours(transactionWithdrawal.getChannelName(),start, end, 5);
				// 记录数据
				recordSetStatisticsDataAndHours(transactionWithdrawalExpect, transactionWithdrawalReal);
			}
		}
	}



	/**
	 * 渠道名称 	商户名称  按小时
	 */
	public void statisticsWithdrawalByChannelAndMerchantAndHours(List<TransactionWithdrawal> channelWithdrawalList, List<MpMerchantRSP> merchantWithdrawalList, String start, String end) {
		if (channelWithdrawalList.size() > 0 && merchantWithdrawalList.size() > 0) {
			for (TransactionWithdrawal channelWithdrawal : channelWithdrawalList) {
				for (MpMerchantRSP merchantWithdrawal : merchantWithdrawalList) {
					// 预期数据
					TransactionWithdrawal transactionWithdrawalExpect = withdrawalMapper.selectByChannelNameAndMerchantNameAndHours(channelWithdrawal.getChannelName(), merchantWithdrawal.getName(), start, end);
					// 实际数据
					TransactionWithdrawal transactionWithdrawalReal = withdrawalMapper.selectByChannelNameAndMerchantNameAndStatusAndHours(channelWithdrawal.getChannelName(), merchantWithdrawal.getName(), start, end, 5);
					// 记录数据
					recordSetStatisticsDataAndHours(transactionWithdrawalExpect, transactionWithdrawalReal);
				}
			}
		}
	}




	/**
	 * 商户名称	按小时
	 */
	public void statisticsWithdrawalAndHours(List<MpMerchantRSP> merchantWithdrawalList, String start, String end){
		if (merchantWithdrawalList.size() > 0) {
			for (MpMerchantRSP transactionWithdrawal : merchantWithdrawalList) {
				// 预期数据
				TransactionWithdrawal transactionWithdrawalExpect = withdrawalMapper.selectByMerchantAndHours(transactionWithdrawal.getName(),start, end);
				// 实际数据
				TransactionWithdrawal transactionWithdrawalReal = withdrawalMapper.selectByMerchantAndDayAndStstusAndHours(transactionWithdrawal.getName(),start, end, 5);
				// 记录数据
				recordSetStatisticsDataAndHours(transactionWithdrawalExpect, transactionWithdrawalReal);
			}
		}
	}


	/**
	 * 封装数据并记录  按小时
	 * @param transactionWithdrawalExpect   预期数据
	 * @param transactionWithdrawalReal     实际数据
	 */
	public void recordSetStatisticsDataAndHours(TransactionWithdrawal transactionWithdrawalExpect, TransactionWithdrawal transactionWithdrawalReal) {
		// 统计记录
		StatisticsWithdrawal statisticsWithdrawal = new StatisticsWithdrawal();
		if (StringUtils.isNotBlank(transactionWithdrawalExpect.getChannelName())) {
			statisticsWithdrawal.setChannelId(transactionWithdrawalExpect.getChannelId());
			statisticsWithdrawal.setChannelName(transactionWithdrawalExpect.getChannelName());
			statisticsWithdrawal.setChannelCode(transactionWithdrawalExpect.getChannelCode());
		}else {
			statisticsWithdrawal.setChannelName("");
		}

		if (StringUtils.isNotBlank(transactionWithdrawalExpect.getMerchantName())) {
			statisticsWithdrawal.setMerchantId(transactionWithdrawalExpect.getMerchantId());
			statisticsWithdrawal.setMerchantName(transactionWithdrawalExpect.getMerchantName());
			statisticsWithdrawal.setMerchantCode(transactionWithdrawalExpect.getMerchantCode());
		}else {
			statisticsWithdrawal.setMerchantName("");
		}

		// 预期数据
		statisticsWithdrawal.setExpectTimes(transactionWithdrawalExpect.getMerchantNotifyStatus().longValue());
		statisticsWithdrawal.setExpectFee(transactionWithdrawalExpect.getSubFee());
		statisticsWithdrawal.setExpectChFee(transactionWithdrawalExpect.getChFee());
		statisticsWithdrawal.setExpectMchFee(transactionWithdrawalExpect.getMchFee());
		statisticsWithdrawal.setExpectFinFee(transactionWithdrawalExpect.getFinFee());
		// 实际数据
		if (transactionWithdrawalReal.getChFee() == null) {
			statisticsWithdrawal.setRealTimes(transactionWithdrawalReal.getMerchantNotifyStatus().longValue());
			statisticsWithdrawal.setRealFee(new BigDecimal("0.00"));
			statisticsWithdrawal.setRealChFee(new BigDecimal("0.00"));
			statisticsWithdrawal.setRealMchFee(new BigDecimal("0.00"));
			statisticsWithdrawal.setRealFinFee(new BigDecimal("0.00"));
		}else {
			statisticsWithdrawal.setRealTimes(transactionWithdrawalReal.getMerchantNotifyStatus().longValue());
			statisticsWithdrawal.setRealFee(transactionWithdrawalReal.getFee());
			statisticsWithdrawal.setRealChFee(transactionWithdrawalReal.getChFee());
			statisticsWithdrawal.setRealMchFee(transactionWithdrawalReal.getMchFee());
			statisticsWithdrawal.setRealFinFee(transactionWithdrawalReal.getFinFee());
		}
		// 插入时间
		// 获取昨天的日期  时分秒
		Calendar calendar = Calendar.getInstance();
		int day = calendar.get(Calendar.DATE);
		calendar.set(Calendar.DATE,day);
		String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
		statisticsWithdrawal.setStatisticsTime(date);
		// 统计时间  昨天的数据   小时区间
		String dateType = getDateType();
		statisticsWithdrawal.setDateType(dateType);
		// 统计类型
		statisticsWithdrawal.setStatisticsType(2);
		// 插入数据
		statisticsWithdrawalMapper.insertStatisticsWithdrawal(statisticsWithdrawal);
	}




	/**
	 * 获取日期    昨天  前7天    前一个月
	 * @param count 查询天数
	 * @return		日期
	 */
	public String getSelectDate(int count){
		if (count > 1) {
			Calendar calendarOne = Calendar.getInstance();
			int dayOne = calendarOne.get(Calendar.DATE);
			calendarOne.set(Calendar.DATE, dayOne - 1);
			String dateOne = new SimpleDateFormat("yyyy-MM-dd").format(calendarOne.getTime());

			Calendar calendarTwo = Calendar.getInstance();
			int dayTwo = calendarTwo.get(Calendar.DATE);
			calendarTwo.set(Calendar.DATE, dayTwo - 1);
			String dateOTwo = new SimpleDateFormat("yyyy-MM-dd").format(calendarTwo.getTime());

			return dateOne + "~" + dateOTwo;
		}else {
			Calendar calendar = Calendar.getInstance();
			int day = calendar.get(Calendar.DATE);
			calendar.set(Calendar.DATE, day - 1);
			String date = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
			return date;
		}
	}




	public String getDateType(){
		// 统计时间类型  昨天的数据   天
		Calendar calendarDateType = Calendar.getInstance();
		int dayDateType = calendarDateType.get(Calendar.DATE);
		calendarDateType.set(Calendar.DATE, dayDateType - 1);
		String day = new SimpleDateFormat("yyyy-MM-dd").format(calendarDateType.getTime());

		// 当前小时
		SimpleDateFormat formatHours = new SimpleDateFormat("HH:mm:ss");
		Calendar calCurHours = Calendar.getInstance();
		String CurHours = formatHours.format(calCurHours.getTime());

		// 上一个小时
		calCurHours.set(Calendar.HOUR_OF_DAY, calCurHours.get(Calendar.HOUR_OF_DAY)-1);
		String aftHours = formatHours.format(calCurHours.getTime());
		String dateType = day  + "   " + aftHours;

		return dateType;
	}

}

